<?php

/**
 * * checking data input
 * @author DuongNV
 * @copyright Tan MA JSC
 * @category common function
 * @version 1.1
 */

/**
 * Check URL exist
 * @param unknown_type $table
 * @param unknown_type $url
 * @param unknown_type $id
 * @return string unknown
 */
function checkURLExist($table, $url, $id) {

    $db = new DBAccess();
    if ($id == 0) {
        $count = $db->selectCountRecord( DATATYPE, array(DATATYPE_ITEMURL => $url));
    } else {
        $count = $db->selectCountDifficultRecord( DATATYPE, array(
                        array(COLUMN => DATATYPE_ITEMURL, KEY => EQUAL, VALUE => $url), 
                        SQL_AND, 
                        array(COLUMN => DATATYPE_ITEMID, KEY => NOT_EQUAL, VALUE => $id),
                        SQL_AND, 
                        array(COLUMN => DATATYPE_TABLENAME, KEY => EQUAL, VALUE => $table)
                        )
                        );
        $count += $db->selectCountDifficultRecord( DATATYPE, array(
                        array(COLUMN => DATATYPE_ITEMURL, KEY => EQUAL, VALUE => $url), 
                        SQL_AND, 
                        array(COLUMN => DATATYPE_TABLENAME, KEY => NOT_EQUAL, VALUE => $table)
                        )
                        );
    }
    
    if ($count > 0) {
        return true;
    } else {
        return false;
    }
}
?>
